package com.cuit.freshmanMS.controller;

import com.cuit.freshmanMS.domain.Admin;
import com.cuit.freshmanMS.service.AdminService;
import com.cuit.freshmanMS.util.StringUtil;
import com.cuit.freshmanMS.util.result.CommonResult;
import com.cuit.freshmanMS.util.result.PageResult;
import com.cuit.freshmanMS.util.result.ResultCode;
import com.cuit.freshmanMS.util.result.ResultUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @description:
 * @author: ziger
 * @time: 2024/1/17 11:35
 */

//@CrossOrigin
@RequestMapping("/admin")
@RestController
public class AdminController {

    @Autowired
    private AdminService adminService;

    @PostMapping("/login")
    CommonResult<Boolean> login(@RequestBody Admin admin) {

        return adminService.login(admin);

    }

    @GetMapping(value = "")
    PageResult<Admin> selectAll(@RequestParam("currentPage") Integer currentPage,
                                @RequestParam("pageSize") Integer pageSize,
                                @RequestParam("keyword") String keyword) {
        return adminService.selectAll(currentPage, pageSize, keyword);
    }

    @PostMapping("")
    CommonResult add(@RequestBody Admin admin) {
        return adminService.add(admin);

    }

    @PutMapping("")
    CommonResult update(@RequestBody Admin admin) {
        return adminService.update(admin);
    }

    @DeleteMapping("/{id}")
    CommonResult delete(@PathVariable Integer id) {
        return adminService.delete(id);
    }

    @DeleteMapping("/deleteBatch")
    CommonResult deleteBatch(@RequestBody List<Integer> ids) {
        return adminService.deleteBatch(ids);
    }
}
